/**
 * copy a file content to another file
 */
package cn.netjava.softkid.chapter06;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author softkid
 * 
 */
public class FileCopy {

	/**
	 * copy the content of src to des
	 * 
	 * @param src:source file
	 * @param des:destination file
	 * @throws IOException
	 */
	public void copyFile(String src, String des) throws IOException {
		java.io.InputStream fis = new FileInputStream(src);
		java.io.BufferedInputStream bins = new java.io.BufferedInputStream(fis);

		java.io.OutputStream fos = new FileOutputStream(des);
		java.io.BufferedOutputStream bous = new java.io.BufferedOutputStream(
				fos);

//		byte[] b = new byte[10];
		int i = -1;
		while ((i = fis.read()) != -1) {
			fos.write(i);

		}
		fos.flush();
		fos.close();
		fis.close();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		FileCopy fc = new FileCopy();
		try {

			long start = System.currentTimeMillis();
			fc.copyFile("D:songs.rar", "D:copy1.rar");
			long end = System.currentTimeMillis();
			long costTime = end - start;
			System.out.println(costTime);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
